#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
const int maxn = 5e5 + 2;
long long n, arr[maxn];
vector<long long> pipe;
long long merge(int ll, int lr, int rl, int rr)
{
    //求出(all,...,alr) 与 (arl,...,arr)合并后的逆序数
    //注意此时的两个子序列都应该是有序的,这样可以避免二重循环:)
    long long res = 0, i = ll, j = rl, factor = 0;
    while (i <= lr && j <= rr)
    {
        if (arr[i] <= arr[j])
            pipe.push_back(arr[i++]), res += factor;
        else if (arr[i] > arr[j])
            pipe.push_back(arr[j++]), factor++;
    }
    if (i <= lr)
        for (; i <= lr; ++i)
            res += factor, pipe.push_back(arr[i]);
    if (j <= rr)
        for (; j <= rr; ++j)
            pipe.push_back(arr[j]), factor++;
    for (int i = ll; i <= rr; ++i)
    {
        arr[i] = pipe[i - ll];
    }
    pipe.clear();
    return res;
}
long long invCount(int l, int r)
{
    if (r <= l)
        return 0;
    long long mid = (l + r) / 2, res = 0;
    res = invCount(l, mid) + invCount(mid + 1, r);
    res += merge(l, mid, mid + 1, r);
    return res;
}
int main()
{
    scanf("%lld", &n);
    for (int i = 0; i < n; ++i)
        scanf("%lld", &arr[i]);
    printf("%lld", invCount(0, n - 1));
    return 0;
}